'use strict';
const fs = require("fs")
const path = require("path")
const Controller = require('egg').Controller;

class DoFileController extends Controller {
  async index() {
    const {ctx} = this
    var {name,age,sex} = ctx.request.body
    // var logo = ctx.request.files[0].filepath
    // var uploadFile = `../public/${path.basename(logo)}`
    /* fs.writeFile(uploadFile,logo,{flag:"w"},function(err){
        if(!err){
            console.log("写入成功");
        }else{
            console.log(err);
        }
    })
    console.log(ctx.origin); */
    var db =  this.app.mongodb;
    await db.collection("user").insertOne({name,age,sex})
    ctx.redirect("/home")
  }
}

module.exports = DoFileController;
